home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 3 / Precision Software Applications Silver Collection Volume Three (PSM) (1993).iso / music2 / mepody.exe / PLAY.C < prev    next >
Text File  |  1991-04-13  |  1KB  |  49 lines

  1. /*                     Play function by A.A.Efros.
  2.     PLAY is C function to be used with MELODY MASTER Data files.
  3.  
  4.   PLAY uses Sound, Delay and Nosound functions. There are no such functions
  5.   in some C-Compilers. In this case one should use file TONE.C (#include
  6.   <tone.c>) which is also included in this package.
  7.  
  8.   To call function PLAY one should:
  9.      play( [FileName], [MelodyName]);
  10.   For example:
  11.      play('music.dat','Glory');
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <dos.h>
  16.  
  17. play(filename, melodyname)
  18.  
  19. char filename[11], melodyname[15];
  20. {
  21.   int q = 1, fr, t, ver = 1;
  22.   char ch, st[1000];
  23.   FILE *data;
  24.  
  25.   if ((data = fopen(filename,"r")) != NULL)
  26.   {
  27.     while (q)
  28.     {
  29.       fscanf(data, "%s", st);
  30.       if ((ver = strcmp(melodyname, st)) == 0)
  31.       {
  32.         do
  33.         {
  34.          q = fscanf(data,"%d%d%c", &fr, &t, &ch);
  35.       sound(fr);
  36.           delay(t);           /*  tone(fr,t); for others compilers */
  37.           nosound();
  38.         } while (ch != '\n' && q != EOF);
  39.         break;
  40.       }
  41.       q = (fgets(st,1000,data) != NULL);
  42.     }
  43.     fclose(data);
  44.     if (ver != 0)
  45.       printf("\007 %s song is not found!\n", melodyname);
  46.   }
  47.   else
  48.     printf("\007 %s file is not found!\n", filename);
  49. }